﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Win.CSkin.Test.Properties;

namespace Win.CSkin.Test
{
    public partial class UC_UserLogin : UserControl
    {
        private bool _User_Login;
        private string _UserID;
        private string _UserName;
        private Enum_UI.UserSex _UserSex = Enum_UI.UserSex.未知;
        //定义委托
        public delegate void LoginBtnClickHandle(object sender, EventArgs e);

        //定义事件
        [Browsable(true)]
        [Description("登入")]
        public event LoginBtnClickHandle UserLoginClick;
        //定义事件
        [Browsable(true)]
        [Description("登出")]
        public event LoginBtnClickHandle UserLogoutClick;

        public UC_UserLogin()
        {
            InitializeComponent();
        }

        [Browsable(true)]
        [Description("设置登录状态")]
        public bool User_Login
        {
            get
            {
                return _User_Login;
            }
            set
            {
                _User_Login = value;
                if (_User_Login)
                {
                    this.BackColor = System.Drawing.Color.LightGreen;
                    lblNo.Visible = false;
                }
                else
                {
                    this.BackColor = System.Drawing.Color.Wheat;
                    lblNo.Visible = true;
                    User_ID = string.Empty;
                    User_Name = string.Empty;
                    User_Sex = Enum_UI.UserSex.未知;
                }
            }
        }

        [Browsable(true)]
        [Description("设置用户代码")]
        public string User_ID
        {
            get
            {
                return _UserID;
            }
            set
            {
                _UserID = value;
                lblID.Text = value;
            }
        }


        [Browsable(true)]
        [Description("设置用户姓名")]
        public string User_Name
        {
            get
            {
                return _UserName;
            }
            set
            {
                _UserName = value;
                lblName.Text = value;
            }
        }


        [Browsable(true)]
        [Description("用户拼音检索码")]
        public string User_PYCode
        {
            get;
            set;
        }

        [Browsable(true)]
        [Description("用户性别")]
        public Enum_UI.UserSex User_Sex
        {
            get
            {
                return _UserSex;
            }
            set
            {
                _UserSex = value;
                switch (_UserSex)
                {
                    case Enum_UI.UserSex.女:
                        picDrug.Image = Resources.ys_fm;
                        break;
                    case Enum_UI.UserSex.男:
                        picDrug.Image = Resources.ys_m;
                        break;
                    default:
                        picDrug.Image = Resources.药师;
                        break;
                }
            }
        }

        public void UserLogin_Click(object sender, EventArgs e)
        {
            UserLoginClick?.Invoke(this, new EventArgs());
            //Item_Selected(true);
            this.Focus();
        }
        public void UserLogout_Click(object sender, EventArgs e)
        {
            UserLogoutClick?.Invoke(this, new EventArgs());
        }

        private void UC_UserLogin_Click(object sender, System.EventArgs e)
        {
            if (this.User_Login)
            {
                UserLogout_Click(sender, e);
            }
            else
            {
                UserLogin_Click(sender, e);
            }
        }

        private void lblNo_Click(object sender, EventArgs e)
        {
            if (this.User_Login)
            {
                UserLogout_Click(sender, e);
            }
            else
            {
                UserLogin_Click(sender, e);
            }
        }

        private void picDrug_Click(object sender, EventArgs e)
        {
            if (this.User_Login)
            {
                UserLogout_Click(sender, e);
            }
            else
            {
                UserLogin_Click(sender, e);
            }
        }

        private void lbl1_Click(object sender, EventArgs e)
        {
            if (this.User_Login)
            {
                UserLogout_Click(sender, e);
            }
            else
            {
                UserLogin_Click(sender, e);
            }
        }

        private void lblID_Click(object sender, EventArgs e)
        {
            if (this.User_Login)
            {
                UserLogout_Click(sender, e);
            }
            else
            {
                UserLogin_Click(sender, e);
            }
        }

        private void lblName_Click(object sender, EventArgs e)
        {
            if (this.User_Login)
            {
                UserLogout_Click(sender, e);
            }
            else
            {
                UserLogin_Click(sender, e);
            }
        }

        private void lbl2_Click(object sender, EventArgs e)
        {
            if (this.User_Login)
            {
                UserLogout_Click(sender, e);
            }
            else
            {
                UserLogin_Click(sender, e);
            }
        }

    }
}
